home *** CD-ROM | disk | FTP | other *** search
/ QRZ! Ham Radio 8 / QRZ Ham Radio Callsign Database - Volume 8.iso / mac / files / dsp / dska_10.hqx / dska ƒ / hostspec.asm < prev    next >
Assembly Source File  |  1994-08-07  |  10KB  |  293 lines

  1. ;-----------------------------------------------------------;
  2. ; HOSTSPEC.ASM                            ;
  3. ; Written By: Keith Larson                    ;
  4. ;          TMS320Cxx DSP Applications Engineer        ;
  5. ;          Texas Instruments                 ;
  6. ;                                ;
  7. ; USE WITH THE DSKL [G]RAPH OPTION.  THIS OPTION IS DESIGNED;
  8. ; TO RECEIVE A BYTE FROM THE DSK AND OUTPUT IT GRAPHICLY.   ;
  9. ; RUNNING THIS PROGRAM ON DSKD WILL CRASH THE DEBUGGER!     ;
  10. ;                                ;
  11. ; A spectrum analyzer using the DSK and your Host PC.        ;
  12. ; This code does NOT work with DSKD!  It is run from within ;
  13. ; DSKL using DSK_COMM to send data to the host via the RS232;
  14. ; link.  It is slower than DSK_SPEC, but you do not need an ;
  15. ; oscilliscope!                         ;
  16. ;                                ;
  17. ; To run this program, first assemble it using DSKA.        ;
  18. ; Then start DSKL, select 'X' for load and execute.  Then   ;
  19. ; select 'G' for graphics.  To exit, hit any key (except Q) ;
  20. ; since the keyboard is not flushed and 'Q' will quit DSKL  ;
  21. ; entirely!                            ;
  22. ;-----------------------------------------------------------;
  23. YES    .set    1        ;
  24. NO    .set    0        ;
  25. FFT_S        .set    256    ;
  26. ;-----------------------------------------------------------;
  27. AIC_1        .set    0x0C18    ;TB =TA = 6    0000110000011000=0x0C18
  28. AIC_2        .set    0x0205    ;TA'=TA'= 1    0000001000000101=0x0205
  29. AIC_3        .set    0x264e    ;RB =TB = 0x13 0010011001001110=0x264c 44 khz
  30. AIC_CMD     .set    0x0003    ;   COMMAND    0000000000000011=0x0083
  31. ;-----------------------------------------------------------;
  32. BCMD        .set    0xFA10    ;JUMP CMD
  33. BXMIT        .set    0xFA12    ;JUMP XMIT
  34. BXMIT16     .set    0xFA14    ;JUMP XMIT16
  35. BRECV        .set    0xFA16    ;JUMP RECV
  36. BRECV16     .set    0xFA18    ;JUMP RECV16
  37. BCXMIT        .set    0xFA1A    ;JUMP CXMIT
  38. ;----------------------------------------------------------
  39. STAT1        .set    0x72    ;
  40. ACCU_lo     .set    0x78    ;
  41. ACCU_hi     .set    0x79    ;
  42. REAL        .set    0x7a    ;
  43. IMAG        .set    0x7b    ;
  44. TEMPX        .set    0x7c    ;
  45. AUX0        .set    0x7d
  46. AUX1        .set    0x7e
  47. ;----------------------------------------------------------------
  48. ;    SECONDARY VECTOR TABLE LOACTED IN B0 PROGRAM RAM
  49. ;----------------------------------------------------------------
  50.     .include  "mmregs.inc"    ;     > USERCODE SHOULD NOT OVERWRITE DSKD  <
  51.     .ps    0xfa00        ;     > VECTORS.  ON LOAD, INT2 IS RESTORED <
  52.        ;B    start        ;RS   > BY DSKD, BUT TRAP IS NOT        <
  53.        ;B    start        ;INT0
  54.        ;B    start        ;INT1
  55.        ;B    start        ;INT2  > DSKD LOAD IGNORES INT2 VECTOR
  56.        ;B    start        ;TINT
  57.     .ps    0fa0ah        ;
  58.     B    RINT        ;RINT  Branch to receive interrupt routine
  59.     eint            ;XINT  XINT is only for timing, so just return
  60.     ret            ;
  61.       ; Begin TRAP/DSKD Kernal    ;DSKD load does not restore this code!
  62. ;----------------------------------------------------------------
  63. ;    APPLICATION CODE IS LOCATED ABOVE DSKD KERNAL
  64. ;----------------------------------------------------------------
  65.     .ps    0xFB00        ;
  66.     .entry            ;
  67. ;----------------------------------------------------------------
  68. start:    sxf
  69.     ssxm
  70.     sovm            ; catch accumulator overflows
  71.     ldpk    0        ; All direct addressing is to MMRs and B2
  72.     fort    0        ; Serial port : 16 bit
  73.     rtxm            ;          : ext. FSX
  74.     sfsm            ;          ; burst mode
  75.     lack    0x80        ; AIC reset by pulsing /BR (Global Data)
  76.     sach    DXR        ; send 0 to DXR (AIC)
  77.     sacl    GREG        ; 256 * 100 nS /BR pulse
  78.     lrlk    AR0,0xFFFF    ;
  79.     rptk    255        ; read junk from address 0xFFFF
  80.     lac    *,0,AR0     ;
  81.     conf    1        ; B1,B3 as DRAM if direct bootload
  82. ;--------------------------------
  83. AIC_RS    lack    0x20        ; Turn on XINT
  84.     sacl    IMR        ;
  85.     idle            ;
  86.     lalk    AIC_1        ; Load each AIC configuration word
  87.     call    AIC_2nd     ; and load it into the AIC
  88.     lalk    AIC_2        ;
  89.     call    AIC_2nd     ;
  90.     lalk    AIC_3        ;
  91.     call    AIC_2nd     ;
  92.     lalk    AIC_CMD     ;
  93.     call    AIC_2nd     ;
  94. ;----------------------------------------------------------------
  95.     lark    AR7,0        ; Buffer initialy filled
  96.     lack    0x10        ; AIC RINT
  97.     sacl    IMR        ; where INT0 indicates EOC (End Of Conv)
  98.     ;---------------------------------------------------------------
  99.     lark    AR7,0        ; Buffer initialy filled
  100. FFT:    lrlk    AR0,FFT_S/2    ;
  101.     larp    AR0        ; start FFT with AR0=FFTSize
  102. new_stg lrlk    AR1,_D_base    ; AR1 is the TOP BFLY address
  103.     lrlk    AR2,_D_base    ; AR2 is the BOT BFLY address
  104.     lrlk    AR3,_T_base+1    ; AR3 is the TWiddle pointer
  105.     lrlk    AR4,FFT_S/2    ; AR4 counts DFT blocks
  106.     b    n_DFT2,*,AR1    ;
  107. DFT:    mar    *BR0+,AR5    ; complete circular buffer for TW's
  108.     lark    AR5,1        ; set up DFT loop with *BR0+/BANZ
  109.     mar    *BR0+,AR1    ; using 1 cuts *BR0+ loop in half!
  110.     ;----------------------------------------
  111.     ; AR1=Top AR2=Bottom AR3=Twiddle
  112.     ;----------------------------------------
  113. BFLY:    lac    *,14,AR2    ;(imag1+imag2)/4
  114.     add    *,14,AR1    ;
  115.     sach    *+,1,AR2    ;store TOP imag
  116.     sub    *,15        ;(imag1-imag2)/2
  117.     sach    *+,1,AR1    ;store BOT imag
  118.     lac    *,14,AR2    ;(real1+real2)/4
  119.     add    *,14,AR1    ;
  120.     sach    *+,1,AR2    ;store TOP real
  121.     sub    *,15        ;(real1-real2)/2
  122.     sach    *,1,AR5     ;store BOT real
  123.     banz    OK,*BR0+,AR3    ;If at DFT end quit early
  124.     ;------------------------
  125.     mar    *+,AR2        ;clean up TW base (xxx0000+1)
  126.     mar    *+        ;modify BOTom DATA pointer
  127.     mar    *0+        ;
  128.     mar    *0+,AR1     ;
  129. n_DFT2: mar    *0+        ;modify the TOP pointer
  130.     mar    *0+,AR4     ;
  131.     banz    DFT,*0-,AR3    ;dec DFT block count AR4 by OFFset
  132.     larp    AR0        ;
  133.     mar    *BR0+        ;
  134.     banz    new_stg,*    ;if OFFset was 1, now cleared
  135.     b    endFFT        ;
  136.      ;-------------------------
  137. OK    lt    *-,AR2        ;TREG=TWR     *NOTE* Twiddles are Q15
  138.     mpy    *-        ;PREG=REAL*TWR
  139.     ltp    *+,AR3        ;TREG=IMAG     ACCU=REAL*TWR
  140.     mpy    *        ;PREG=IMAG*TWI              AR2=R AR3=I
  141.     lts    *+,AR2        ;TREG=TWI      ACCU=REAL*TWR-IMAG*TWI
  142.     mpy    *        ;PREG=REAL*TWI
  143.     sach    *-,1,AR2     ;<<;
  144.     ltp    *,AR3        ;TREG=IMAG     ACCU=REAL*TWI
  145.     mpy    *BR0+,AR2    ;PREG=IMAG*TWR
  146.     apac            ;           ACCU=IMAG*TWR+REAL*TWI
  147.     sach    *+,1,AR2     ;<<;
  148.     b    BFLY,*+,AR1    ;
  149.     ;------------------------------------------------------------
  150. endFFT: larp    AR2        ;Transform REAL & IMAG to log magnitude
  151.     lrlk    AR2,_D_base    ;AR3=FFT data pointer
  152.     lrlk    AR3,FFT_S-1    ;AR5=FFT loop counter
  153.     lrlk    AR0,FFT_S
  154.     ;-----------------------------------------------------------;
  155.     ; WINDOW: Performs post FFT raised cosine windowing!        ;
  156.     ; This is done by using the frequency coefficients of the   ;
  157.     ; window in a convolution filter of the spectrum.        ;
  158.     ;-----------------------------------------------------------;
  159.       ;mar    *BR0+           ; don't start at DC
  160. more_MAG
  161.     mar     *BR0-        ;  -IMAG[-1]  1-COS(nwt/N)     + 1
  162.     lac     *BR0+,15    ;   IMAG[-0]  filter by post     |
  163.     subh     *BR0+        ;  +IMAG[+1]  convolution    <--+++-->
  164.     add     *BR0-,15    ;   IMAG            + + -.5
  165.     sach     IMAG        ;
  166.     mar     *+        ;   REAL
  167.     mar     *BR0-        ;  -REAL[-1]
  168.     lac     *BR0+,15    ;   REAL[-0]  X[-1] -2*X[0] + X[1]
  169.     subh     *BR0+        ;  +REAL[+1]
  170.     add     *BR0-,15,AR1    ;   REAL
  171.     sach     REAL        ;
  172.     sqra    IMAG        ;IMAG & REAL can be at most 0x7fff Q15
  173.     ltp    REAL        ;MPY will result (at most) in max positive
  174.     mpy    REAL        ;
  175.     apac            ;output is positive Q30
  176.     addk    0x1        ;Set up a floor value; log(0) not legal!
  177.     lark    AR1,22        ;pre-scaling exponent shifts Y axis
  178.     rptk    31        ;
  179.     norm    *-        ;
  180.     larp    AR2        ;
  181.     mar    *BR0-      ;-REAL;dump log(f) into oldest REAL (odd addr)
  182.     sach    *,2        ;clr explicit 1.0 and sign bit from mant
  183.     zals    *        ;load into ACCU_lo
  184.     sar    AR1,*        ;then append exponent (AR1)
  185.     addh    *        ;
  186.     rptk    10        ;jam result into ACCU_hi
  187.     sfl            ;If needed, Use ADDH to saturate overflow
  188.      ;    sach    *        ;
  189.      ;    addh    *        ;
  190.     sach    *        ;
  191.     lac    *        ;
  192.     andk    0xfffc,0    ;
  193.     sacl    *BR0+        ; REAL
  194.     mar    *-        ; IMAG
  195.     mar    *BR0+,AR3    ;+IMAG
  196.     banz    more_MAG,*-,AR2 ;keep going until all done
  197.     ;--------------------------------------------------------
  198. BITREV: lrlk    AR0,FFT_S    ;Now perform Output bit reversal
  199.     lrlk    AR1,_D_base    ;by moving the magnitude, which
  200.     lrlk    AR2,_D_base+1    ;is in the REAL slots, into the
  201.     lrlk    AR3,FFT_S-1    ;IMAG slots of the FFT data array
  202. more_BR lac    *+        ;load the magnitude
  203.     mar    *+,AR1        ;
  204.     sacl    *BR0+,0,AR3    ;move it to an open IMAG slot
  205.     banz    more_BR,*-,AR2    ;more data to move?
  206.     ;--------------------------------------------------------
  207. MOVE_IO larp    AR7        ;wait until buffer is full
  208.     banz    MOVE_IO,*,AR2    ;(AR7 is decremented by ISR)
  209.     ;------------------------
  210.     lrlk    AR3,_D_base    ;AR3=FFT data pointer
  211.     lrlk    AR4,_B_base    ;AR4=BUFF data pointer
  212.     lrlk    AR5,FFT_S-1    ;AR5=FFT loop counter
  213.     lrlk    AR6,_B_base    ;AR6=ISR BUFF data pointer
  214.     lrlk    AR7,FFT_S-1    ;AR7=ISR BUFF loop counter
  215.     ;-------------------------
  216.     dint
  217.     zac
  218.     call    DAT2HOST
  219.     larp    AR2
  220. more_IO
  221.     lar    AR2,*,AR3    ;Get A/D value from buffer
  222.     lac    *,0,AR4     ;ACCU= log magnitude (from even address)
  223.     sacl    *+,0,AR3    ;
  224.  
  225.     rptk    7
  226.     sfr
  227.     ork    1
  228.     call    DAT2HOST
  229.     larp    AR3
  230.  
  231.     zac            ;
  232.     sach    *+,0        ;IMAG=0
  233.     sar    AR2,*+,AR5    ;
  234.  
  235.     banz    more_IO,*-,AR4    ;
  236.     eint            ; BUFF clear so enable INT's
  237.     b    FFT        ;
  238. ;-----------------------------------------------------------------
  239. RINT:    sst1    STAT1        ;Recover ARP from ARB by LST1 last
  240.     larp    AR7        ;AR6 = current buffer position
  241.     banz    more_buf,*-,AR6 ;if buffer is full RET w/o EINT
  242.     lark    AR7,0        ;
  243.     lst1    STAT1        ;
  244.     ret            ;
  245. more_buf            ;
  246.     sacl    ACCU_lo     ;Use NORM start val to adj Y offset
  247.     sach    ACCU_hi     ;post log convert scaling ajsts magnitude
  248.     zalh    *        ;Get value
  249.     sach    DXR        ;
  250.     ;------------------------
  251.     lac    DRR        ;
  252.     bit    TEMPX,15    ;Inverting every other input aliases the
  253.     bbz    NO_NVRT     ;frequency domain, swapping DC and Nyquist!
  254.     neg            ;
  255. NO_NVRT             ;
  256.     sacl    *+        ;<<< store DRR, and point to next
  257.     lac    TEMPX        ;
  258.     xork    1        ;
  259.     sacl    TEMPX        ;
  260.     zalh    ACCU_hi     ;
  261.     adds    ACCU_lo     ;
  262.     lst1    STAT1        ;
  263.     eint            ;
  264.     ret            ;
  265. ******************************************************************
  266. AIC_2nd adlk    6,15        ;set ACCU_hi = 3 for secondary XMIT
  267.     idle            ;Wait for a XINT
  268.     sach    DXR        ;
  269.     idle            ;ACCU_hi requests 2nd XMIT
  270.     sacl    DXR        ;
  271.     idle            ;ACCU_lo sets up registers
  272.     sacl    DXR,2        ;close command with LSB = 00
  273.     idle            ;
  274.     eint            ;
  275.     ret            ;
  276. ********************************************************************
  277. DAT2HOST sacl      ACCU_lo    ;
  278.      sach      ACCU_hi    ;
  279.      sar      AR0,AUX0    ;
  280.      sar      AR1,AUX1    ;
  281.      call      BXMIT     ;
  282.      zals      ACCU_lo    ;
  283.      addh      ACCU_hi    ;
  284.      lar      AR0,AUX0    ;
  285.      lar      AR1,AUX1    ;
  286.      ret            ;
  287. ;====================================================================
  288.     .listoff        ;
  289.     .ds    0x400        ;NOTE: Twiddles are relocated to
  290.     .include "dsk_twid.inc" ;      0x400 (B2) using CONF 1
  291.     .liston
  292.     .end
  293.